package com.manager.controller;

import com.manager.bean.Building;
import com.manager.service.BuildingService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

import com.manager.bean.PageInfo;

/**
 * (Building)表控制层
 *
 * @author makejava
 * @since 2021-03-02 20:15:29
 */
@Controller
public class BuildingController {
    /**
     * 服务对象
     */
    @Resource
    private BuildingService buildingService;

    @RequestMapping(value = "/findBuilding")
    public String findBuilding(Model model,Integer pageIndex,Integer pageSize) {
        PageInfo<Building> pi = buildingService.findPageInfo(pageIndex,pageSize);
        model.addAttribute("pi", pi);
        return "building_list";
    }


    @RequestMapping(value = "/exportbuildinglist", method = RequestMethod.POST)
    @ResponseBody
    public List<Building> exportBuilding() {
        List<Building> buildingList = buildingService.getAll();
        return buildingList;
    }


    @RequestMapping("/deleteBuilding")
    @ResponseBody
    public String deleteBuilding(Integer Id) {
        boolean s = buildingService.deleteById(Id);
        return "building_list";
    }


    @RequestMapping(value = "/addBuilding", method = RequestMethod.POST)
    @ResponseBody
    public String addBuilding(@RequestBody Building building) {
        buildingService.insert(building);
        return "building_list";
    }


    @RequestMapping(value = "/updateBuilding", method = RequestMethod.POST)
    public String updateBuilding(Building building) {
        buildingService.update(building);
        return "redirect:/findBuilding";
    }


    @RequestMapping("/findBuildingById")
    public String findBuildingById(Integer Id, HttpSession session, Model model) {
        Building s = buildingService.queryById(Id);
        session.setAttribute("s", s);
        model.addAttribute("s", s);
        return "building_edit";
    }

}
